﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Newtonsoft.Json;

namespace KDSugar.Galaxy.API.Base
{
    /// <summary>
    /// 携带了编号和内码的操作指令抽象类
    /// </summary>
    public abstract class BaseNumberId : BaseCommand
    {
        /// <summary>
        /// 携带了编号和内码的操作指令抽象类|初始化
        /// </summary>
        /// <param name="_url"></param>
        /// <param name="_formId"></param>
        /// <param name="_client"></param>
        public BaseNumberId(string _url,string _formId,GalaxyCloudAPIClient _client)
            : base(_url, _formId, _client)
        {

        }

        /// <summary>
        /// 携带了编号和内码的操作指令抽象类|初始化
        /// </summary>
        /// <param name="_url"></param>
        /// <param name="_formId"></param>
        /// <param name="_opNumber"></param>
        /// <param name="_client"></param>
        public BaseNumberId(string _url, string _formId, string _opNumber, GalaxyCloudAPIClient _client)
            : base(_url, _formId, _opNumber, _client)
        {

        }

        /// <summary>
        /// 标识依据
        /// </summary>
        [JsonIgnore]
        public Constant.FormIdTagTypeEnum FormIdTagType
        {
            get
            {
                return formIdTagType;
            }
            set
            {
                //如果带入的标识依据与之前的不一样的话，则需要把之前的作个清除
                if (formIdTagType != value)
                {
                    switch (formIdTagType)
                    {
                        case Constant.FormIdTagTypeEnum.BillNo:
                            Number = null;
                            break;
                        case Constant.FormIdTagTypeEnum.FID:
                            Id = null;
                            break;
                        case Constant.FormIdTagTypeEnum.EntryId:
                            CleanEntryId();
                            break;
                    }
                }
                formIdTagType = value;
            }
        }

        private Constant.FormIdTagTypeEnum formIdTagType = Constant.FormIdTagTypeEnum.FID;

        /// <summary>
        /// 单据编码集合
        /// </summary>
        public string Number { get; private set; }

        /// <summary>
        /// 设置单据编码集合
        /// </summary>
        /// <param name="_number">单据编码</param>
        public void SetNumber(string _number)
        {
            Number = _number;
            FormIdTagType = Constant.FormIdTagTypeEnum.BillNo;
        }

        ///// <summary>
        ///// 追加新的单据编码到单据编码集合
        ///// </summary>
        ///// <param name="_number">单据编码</param>
        //public void AppendNumbers(string _number)
        //{
        //    var _numbers = Number;
        //    Helper.AppendArrays(ref _numbers, _number);
        //    Number = _numbers;
        //    FormIdTagType = Constant.FormIdTagTypeEnum.BillNo;
        //}

        /// <summary>
        /// 单据内码集合
        /// </summary>
        public string Id { get; private set; }

        /// <summary>
        /// 设置单据内码集合
        /// </summary>
        /// <param name="_id">
        /// 单据内码
        /// </param>
        public void SetId(string _id)
        {
            Id = _id;
            FormIdTagType = Constant.FormIdTagTypeEnum.FID;
        }

        ///// <summary>
        ///// 设置单据内码集合
        ///// </summary>
        ///// <param name="_ids">单据内码集合</param>
        //public void SetIds(List<long> _ids)
        //{
        //    Id = Helper.ArraysToString(_ids);
        //    FormIdTagType = Constant.FormIdTagTypeEnum.FID;
        //}

        /// <summary>
        /// 清理分录内码集合
        /// </summary>
        public virtual void CleanEntryId()
        {

        }
    }
}
